package com.siwei.mes.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.siwei.mes.common.query.PageQuery;
import com.siwei.mes.entity.TestProjectInfo;
import com.siwei.mes.mapper.TestProjectInfoMapper;
import com.siwei.mes.service.TestProjectInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

import static com.siwei.mes.common.exception.handler.MessageHandler.assertTrue;

/**
 * 试验项目配置(TestProjectInfo)表服务实现类
 *
 * @author linzi
 * @since 2023-12-21 21:01:52
 */
@Service
public class TestProjectInfoServiceImpl implements TestProjectInfoService {
    private static final Logger log = LoggerFactory.getLogger("tgl");
    @Resource
    private TestProjectInfoMapper testProjectInfoMapper;

    @Override
    public Long create(TestProjectInfo entity) {
        testProjectInfoMapper.insertSelective(entity);
        return entity.getId();
    }

    @Override
    public void update(TestProjectInfo entity) {
        TestProjectInfo testProjectInfo = testProjectInfoMapper.selectByPrimaryKey(entity.getId());
        assertTrue(testProjectInfo == null, "试验项目配置信息不存在");
        testProjectInfoMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public void delete(Long id) {
        TestProjectInfo testProjectInfo = testProjectInfoMapper.selectByPrimaryKey(id);
        assertTrue(testProjectInfo == null, "试验项目配置信息不存在");
        testProjectInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo<TestProjectInfo> getPage(PageQuery<TestProjectInfo, TestProjectInfo> query) {
        TestProjectInfo searchParam = query.getParams();
        return PageHelper.startPage(query.getPageNum(), query.getPageSize())
                .doSelectPageInfo(() -> testProjectInfoMapper.getList(searchParam));
    }

    @Override
    public TestProjectInfo loadById(Long id) {
        return testProjectInfoMapper.loadById(id);
    }

    @Override
    public List<TestProjectInfo> getAll(TestProjectInfo entity) {
        return testProjectInfoMapper.getList(entity);
    }
}
